package cn.gson.boot.controller;

import cn.gson.boot.model.pojos.*;
import cn.gson.boot.model.service.AttributeService;
import cn.gson.boot.model.service.CategoryService;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    CategoryService categoryService;

    /**
     * 查询所有规格类别
     * @return
     */
    @RequestMapping("/selectCategory")
    @ResponseBody
    public List<CategoryType> selectCategory(){
        List<CategoryType> categorys = categoryService.selectAllCategory();
        return categorys;
    }

    /**
     * 修改类别时查询上级类别
     * @param categoryId
     */
    @RequestMapping("/selectCategoryIdt")
    @ResponseBody
    public Category selectCategoryIdt(Integer categoryId){
        return categoryService.selectCategoryIdt(categoryId);
    }

    /**
     * 新增类别
     * @param category
     */
    @RequestMapping("/addCategory")
    @ResponseBody
    public void addCategory(@RequestBody Category category){
        categoryService.addCategory(category);
    }


    /**
     * 删除时查询是否有下级类别
     * @param categoryId
     */
    @RequestMapping("/selectCategoryt")
    @ResponseBody
    public List<Category> selectCategoryt(Integer categoryId) {
        return categoryService.selectCategoryt(categoryId);
    }

    /**
     * 删除类别
     * @param categoryId
     */
    @RequestMapping("/delCategory")
    @ResponseBody
    public void delCategory(Integer categoryId) {
        categoryService.delCategory(categoryId);
    }

}
